home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWGadgts / Sources / FWContrH.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  23.1 KB  |  705 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWContrH.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifdef FW_BUILD_MAC
  11.  
  12. #include "FWFrameW.hpp"
  13.  
  14. #ifndef FWCONTRH_H
  15. #include "FWContrH.h"
  16. #endif
  17.  
  18. #ifndef FWSCLBAR_H
  19. #include "FWSclBar.h"
  20. #endif
  21.  
  22. #ifndef FWPUSHBU_H
  23. #include "FWPushBu.h"
  24. #endif
  25.  
  26. #ifndef FWRADIOB_H
  27. #include "FWRadioB.h"
  28. #endif
  29.  
  30. // ----- OS Layer -----
  31.  
  32. #ifndef FWGRGLOB_H
  33. #include "FWGrGlob.h"
  34. #endif
  35.  
  36. // ----- Foundation Layer -----
  37.  
  38. #ifndef FWNOTIFN_H
  39. #include "FWNotifn.h"
  40. #endif
  41.  
  42. #ifndef FWINTERE_H
  43. #include "FWIntere.h"
  44. #endif
  45.  
  46. #ifndef FWBNDSTR_H
  47. #include "FWBndStr.h"
  48. #endif
  49.  
  50. // ----- OpenDoc Includes -----
  51.  
  52. #ifndef SOM_ODFacet_xh
  53. #include <Facet.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODCanvas_xh
  57. #include <Canvas.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODTransform_xh
  61. #include <Trnsform.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODShape_xh
  65. #include <Shape.xh>
  66. #endif
  67.  
  68. //========================================================================================
  69. // Runtime Informations
  70. //========================================================================================
  71.  
  72. #if FW_LIB_EXPORT_PRAGMAS
  73. #pragma lib_export on
  74. #endif
  75.  
  76. #ifdef FW_BUILD_MAC
  77. #pragma segment fwgadgts
  78. #endif
  79.  
  80. FW_DEFINE_CLASS_M0(FW_CPrivMacControlHelper)
  81.  
  82. //========================================================================================
  83. // Globales
  84. //========================================================================================
  85.  
  86. WindowPtr FW_CPrivMacControlHelper::gScratchWindow;
  87.  
  88. //========================================================================================
  89. // STRUCT FW_SPrivControlOwner
  90. //========================================================================================
  91. // SetupControl, RestoreControl need to be reentrant, so we keep a stack of control owners.
  92. // A new entry is placed on the stack everytime SetupControl is called and removed every-
  93. // time RestoreControl is called.
  94.  
  95. struct FW_SPrivControlOwner
  96. {
  97.     FW_SPrivControlOwner(WindowPtr window, FW_SPrivControlOwner* nextOwner) :
  98.         fWindow(window), fNextOwner(nextOwner) { }
  99.  
  100.     WindowPtr                fWindow;
  101.     FW_SPrivControlOwner*    fNextOwner;
  102. };
  103.  
  104. //========================================================================================
  105. // CLASS FW_CPrivMacControlHelper
  106. //========================================================================================
  107.  
  108. //----------------------------------------------------------------------------------------
  109. // FW_CPrivMacControlHelper::FW_CPrivMacControlHelper
  110. //----------------------------------------------------------------------------------------
  111.  
  112. FW_CPrivMacControlHelper::FW_CPrivMacControlHelper(Environment* ev,
  113.                                                 const FW_CClassInfo& classInfo,
  114.                                                 FW_CGadget* gadget) :
  115.     fGadget(gadget),
  116.     fControlHandle(NULL),
  117.     fControlOwnerHead(NULL),
  118.     fControlMargin(0, 0, 0, 0)
  119. {
  120.     CheckForInitialize(ev, classInfo);
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. // FW_CPrivMacControlHelper::~FW_CPrivMacControlHelper
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_CPrivMacControlHelper::~FW_CPrivMacControlHelper()
  128. {
  129.     if (fControlHandle)
  130.         ::DisposeControl(fControlHandle);
  131.     
  132.     if (gScratchWindow)
  133.     {
  134.         long count;
  135.         ::SetWRefCon(gScratchWindow,  count = (::GetWRefCon(gScratchWindow) - 1));
  136.         if (count == 0)
  137.         {
  138.             ::DisposeWindow(gScratchWindow);
  139.             gScratchWindow = NULL;
  140.         }
  141.     }
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // FW_CPrivMacControlHelper::CheckForInitialize
  146. //----------------------------------------------------------------------------------------
  147.  
  148. void FW_CPrivMacControlHelper::CheckForInitialize(Environment* ev, const FW_CClassInfo& classInfo)
  149. {
  150.     if (classInfo == FW_TYPEID_FROM_POINTER(this))
  151.         this->Initialize(ev);
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // FW_CPrivMacControlHelper::Initialize
  156. //----------------------------------------------------------------------------------------
  157.  
  158. void FW_CPrivMacControlHelper::Initialize(Environment* ev)
  159. {    
  160.     if (gScratchWindow == NULL)
  161.     {
  162.         FW_SPlatformRect rBounds;
  163.         ::SetRect(&rBounds, 0, 0, 10 , 10);
  164.         gScratchWindow = ::NewCWindow(NULL,
  165.                                         &rBounds,
  166.                                         "\p",
  167.                                         false,
  168.                                         documentProc,
  169.                                         NULL,
  170.                                         false,
  171.                                         0);
  172.     }
  173.  
  174.     ::SetWRefCon(gScratchWindow, ::GetWRefCon(gScratchWindow) + 1);
  175.     
  176.     FW_SPlatformPoint qdLocation;
  177.     fGadget->GetLocation(ev).AsPlatformPoint(qdLocation);
  178.     FW_SPlatformPoint qdSize;
  179.     fGadget->GetSize(ev).AsPlatformPoint(qdSize);
  180.  
  181.     fControlHandle = CreateControlHandle(gScratchWindow, qdLocation, qdSize);
  182.                                          
  183.     ::SetControlReference(fControlHandle, (long) this);
  184.  
  185.     // ----- Remove it from the window -----
  186.     ((WindowPeek) gScratchWindow)->controlList = NULL;
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // FW_CPrivMacControlHelper::ControlHandleToControlMgrHelper
  191. //----------------------------------------------------------------------------------------
  192.  
  193. FW_CPrivMacControlHelper *FW_CPrivMacControlHelper::ControlHandleToControlMgrHelper(ControlHandle handle)
  194. {
  195.     return (FW_CPrivMacControlHelper *) ::GetControlReference(handle);
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. // FW_CPrivMacControlHelper::SetControlMargin
  200. //----------------------------------------------------------------------------------------
  201.  
  202. void FW_CPrivMacControlHelper::SetControlMargin(const FW_SPlatformRect& controlMargin)
  203. {
  204.     fControlMargin = controlMargin;
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. // FW_CPrivMacControlHelper::SetBounds
  209. //----------------------------------------------------------------------------------------
  210.  
  211. void FW_CPrivMacControlHelper::SetBounds(const FW_SPlatformRect& controlBounds)
  212. {
  213.     (*fControlHandle)->contrlRect = controlBounds;
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. // FW_CPrivMacControlHelper::SetValue
  218. //----------------------------------------------------------------------------------------
  219.  
  220. void FW_CPrivMacControlHelper::SetValue(WindowPtr window,
  221.                                         const FW_SPlatformPoint& location,
  222.                                         const FW_SPlatformPoint& size,
  223.                                         short value)
  224. {
  225.     SetupControl(window, location, size);
  226.     ::SetControlValue(fControlHandle, value);
  227.      RestoreControl();
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. // FW_CPrivMacControlHelper::SetValue
  232. //----------------------------------------------------------------------------------------
  233.  
  234. void FW_CPrivMacControlHelper::SetValue(short value, FW_Boolean drawUsingCurrentPort)
  235. {
  236.     if (drawUsingCurrentPort)
  237.         ::SetControlValue(fControlHandle, value);
  238.     else
  239.         (*fControlHandle)->contrlValue = value;
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. // FW_CPrivMacControlHelper::SetMin
  244. //----------------------------------------------------------------------------------------
  245.  
  246. void FW_CPrivMacControlHelper::SetMin(short min)
  247. {
  248.     ::SetControlMinimum(fControlHandle, min);
  249. }
  250.  
  251. //----------------------------------------------------------------------------------------
  252. // FW_CPrivMacControlHelper::SetMax
  253. //----------------------------------------------------------------------------------------
  254.  
  255. void FW_CPrivMacControlHelper::SetMax(short max)
  256. {
  257.     ::SetControlMaximum(fControlHandle, max);
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. // FW_CPrivMacControlHelper::SetText
  262. //----------------------------------------------------------------------------------------
  263.  
  264. void FW_CPrivMacControlHelper::SetText(const FW_CString& text)
  265. {
  266.     Str255 pascalText;
  267.     text.ExportPascal(pascalText);
  268.     ::SetControlTitle(fControlHandle, pascalText);
  269. }
  270.  
  271. //----------------------------------------------------------------------------------------
  272. // FW_CPrivMacControlHelper::GetText
  273. //----------------------------------------------------------------------------------------
  274.  
  275. void FW_CPrivMacControlHelper::GetText(FW_CString& text) const
  276. {
  277.     Str255 pascalText;
  278.     ::GetControlTitle(fControlHandle, pascalText);
  279.     text.ReplaceAll(pascalText);
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. // FW_CPrivMacControlHelper::Draw
  284. //----------------------------------------------------------------------------------------
  285.  
  286. void FW_CPrivMacControlHelper::Draw(WindowPtr window, 
  287.                                     const FW_SPlatformPoint& location,
  288.                                     const FW_SPlatformPoint& size)
  289. {
  290.     SetupControl(window, location, size);
  291.     ::Draw1Control(fControlHandle);
  292.      RestoreControl();
  293. }
  294.  
  295. //----------------------------------------------------------------------------------------
  296. // FW_CPrivMacControlHelper::Show
  297. //----------------------------------------------------------------------------------------
  298.  
  299. void FW_CPrivMacControlHelper::Show(WindowPtr window,
  300.                                     const FW_SPlatformPoint& location,
  301.                                     const FW_SPlatformPoint& size)
  302. {
  303.     SetupControl(window, location, size);
  304.     ::ShowControl(fControlHandle);
  305.      RestoreControl();
  306. }
  307.  
  308. //----------------------------------------------------------------------------------------
  309. // FW_CPrivMacControlHelper::Hide
  310. //----------------------------------------------------------------------------------------
  311.  
  312. void FW_CPrivMacControlHelper::Hide(WindowPtr window,
  313.                                     const FW_SPlatformPoint& location,
  314.                                     const FW_SPlatformPoint& size)
  315. {
  316.     SetupControl(window, location, size);
  317.     ::HideControl(fControlHandle);
  318.      RestoreControl();
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. // FW_CPrivMacControlHelper::MouseDown
  323. //----------------------------------------------------------------------------------------
  324.  
  325. Boolean FW_CPrivMacControlHelper::MouseDown(WindowPtr window,
  326.                                         const FW_SPlatformPoint& whereMouse,
  327.                                         const FW_SPlatformPoint& controlLocation,
  328.                                         const FW_SPlatformPoint& controlSize)
  329. {
  330.     SetupControl(window, controlLocation, controlSize);
  331.     RestoreControl();
  332.     
  333.     return FALSE;
  334. }
  335.  
  336. //----------------------------------------------------------------------------------------
  337. // FW_CPrivMacControlHelper::SetupControl
  338. //----------------------------------------------------------------------------------------
  339.  
  340. void FW_CPrivMacControlHelper::SetupControl(WindowPtr window,
  341.                                          const FW_SPlatformPoint& location,
  342.                                          const FW_SPlatformPoint& size)
  343. {
  344.     if (fControlHandle)
  345.     {
  346.         fControlOwnerHead = new FW_SPrivControlOwner((*fControlHandle)->contrlOwner,
  347.                                                      fControlOwnerHead);
  348.         (*fControlHandle)->contrlOwner = window;
  349.         (*fControlHandle)->contrlRect.top = location.v + fControlMargin.top;
  350.         (*fControlHandle)->contrlRect.left = location.h + fControlMargin.left;
  351.         (*fControlHandle)->contrlRect.bottom = location.v + size.v - fControlMargin.bottom;
  352.         (*fControlHandle)->contrlRect.right = location.h + size.h - fControlMargin.right;
  353.     }
  354. }
  355.  
  356. //----------------------------------------------------------------------------------------
  357. // FW_CPrivMacControlHelper::RestoreControl
  358. //----------------------------------------------------------------------------------------
  359.  
  360. void FW_CPrivMacControlHelper::RestoreControl()
  361. {
  362.     if (fControlHandle)
  363.     {
  364.         FW_SPrivControlOwner* saveToDelete = fControlOwnerHead;
  365.         (*fControlHandle)->contrlOwner = fControlOwnerHead->fWindow;
  366.         fControlOwnerHead = fControlOwnerHead->fNextOwner;
  367.         delete saveToDelete;
  368.     }
  369. }
  370.  
  371. //========================================================================================
  372. // CLASS FW_CPrivMacScrollBarHelper
  373. //========================================================================================
  374.  
  375. FW_DEFINE_CLASS_M1(FW_CPrivMacScrollBarHelper, FW_CPrivMacControlHelper)
  376.  
  377. //----------------------------------------------------------------------------------------
  378. // FW_CPrivMacScrollBarHelper::FW_CPrivMacScrollBarHelper
  379. //----------------------------------------------------------------------------------------
  380.  
  381. FW_CPrivMacScrollBarHelper::FW_CPrivMacScrollBarHelper(Environment* ev,
  382.                                                         const FW_CClassInfo& classInfo,
  383.                                                         FW_CScrollBar *scrollBar) :
  384.     FW_CPrivMacControlHelper(ev, classInfo, scrollBar)
  385. {
  386.     CheckForInitialize(ev, classInfo);
  387. }
  388.  
  389. //----------------------------------------------------------------------------------------
  390. // FW_CPrivMacScrollBarHelper::~FW_CPrivMacScrollBarHelper
  391. //----------------------------------------------------------------------------------------
  392.  
  393. FW_CPrivMacScrollBarHelper::~FW_CPrivMacScrollBarHelper()
  394. {
  395. }
  396.  
  397. //----------------------------------------------------------------------------------------
  398. // FW_CPrivMacScrollBarHelper::MouseDown
  399. //----------------------------------------------------------------------------------------
  400.  
  401. Boolean FW_CPrivMacScrollBarHelper::MouseDown(WindowPtr window,
  402.                                        const FW_SPlatformPoint& whereMouse,
  403.                                        const FW_SPlatformPoint& controlLocation,
  404.                                        const FW_SPlatformPoint& controlSize)
  405. {
  406.     SetupControl(window, controlLocation, controlSize);
  407.  
  408.     switch (::TestControl(GetControlHandle(), whereMouse))
  409.     {
  410.         case kControlDownButtonPart:
  411.         case kControlUpButtonPart:
  412.         case kControlPageDownPart:
  413.         case kControlPageUpPart:
  414.             {
  415.                 ControlActionUPP actionProc = NewControlActionProc(&CallActionProc);
  416.                 // Check and throw AMB
  417.                 ::TrackControl(GetControlHandle(), whereMouse, actionProc);
  418.                 DisposeRoutineDescriptor((UniversalProcPtr) actionProc);
  419.             }
  420.             break;
  421.         
  422.         case kControlIndicatorPart:
  423.             {
  424.                 FW_CScrollBar* scrollBar = FW_DYNAMIC_CAST(FW_CScrollBar, GetGadget());
  425.                 FW_ASSERT(scrollBar);
  426.                 
  427.                 short before = GetValue();
  428.                 ::TrackControl(GetControlHandle(), whereMouse, NULL);
  429.                 
  430.                 FW_CFixed fxValue = FW_IntToFixed(GetValue());
  431.                 scrollBar->ScrollPositionChanged(somGetGlobalEnvironment(), fxValue, fxValue - FW_IntToFixed(before));
  432.             }
  433.             break;
  434.     };
  435.     
  436.     RestoreControl();
  437.     
  438.     return TRUE;
  439. }
  440.  
  441. //----------------------------------------------------------------------------------------
  442. // FW_CPrivMacScrollBarHelper::CreateControlHandle
  443. //----------------------------------------------------------------------------------------
  444.  
  445. ControlHandle FW_CPrivMacScrollBarHelper::CreateControlHandle(WindowPtr window,
  446.                                                 const FW_SPlatformPoint& location,
  447.                                                 const FW_SPlatformPoint& size)
  448. {
  449.     FW_SPlatformRect rect(location.h, location.v,
  450.                           location.h + size.h, location.v + size.v);
  451.     
  452.     return ::NewControl(window, &rect, "\p", true,
  453.                         FW_CScrollBar::kDefaultScrollPos,
  454.                         FW_CScrollBar::kDefaultScrollMin,
  455.                         FW_CScrollBar::kDefaultScrollMax,
  456.                         scrollBarProc, 0);
  457. }
  458.  
  459. //----------------------------------------------------------------------------------------
  460. // FW_CPrivMacScrollBarHelper::CallActionProc
  461. //----------------------------------------------------------------------------------------
  462.  
  463. pascal void FW_CPrivMacScrollBarHelper::CallActionProc(ControlHandle controlHandle,
  464.                                                   short partCode)
  465. {
  466.     FW_CPrivMacScrollBarHelper *scrollBarHelper = 
  467.         (FW_CPrivMacScrollBarHelper *) FW_CPrivMacControlHelper::ControlHandleToControlMgrHelper(controlHandle);
  468.     // Check and throw AMB
  469.     scrollBarHelper->ActionProc(partCode);
  470. }
  471.  
  472. //----------------------------------------------------------------------------------------
  473. // FW_CPrivMacScrollBarHelper::ActionProc
  474. //----------------------------------------------------------------------------------------
  475.  
  476. void FW_CPrivMacScrollBarHelper::ActionProc(short partCode)
  477. {
  478.     Environment *ev = somGetGlobalEnvironment();
  479.     
  480.     FW_CScrollBar* scrollBar = FW_DYNAMIC_CAST(FW_CScrollBar, GetGadget());
  481.     FW_ASSERT(scrollBar);
  482.  
  483.     FW_CFixed changeBy = FW_IntToFixed(0);
  484.     
  485.     switch (partCode)
  486.     {
  487.         case kControlDownButtonPart:
  488.             changeBy = scrollBar->GetMinorScrollUnits(ev);
  489.             break;
  490.             
  491.         case kControlUpButtonPart:
  492.             changeBy = -scrollBar->GetMinorScrollUnits(ev);
  493.             break;
  494.             
  495.         case kControlPageDownPart:
  496.             changeBy = scrollBar->GetMajorScrollUnits(ev);
  497.             break;
  498.             
  499.         case kControlPageUpPart:
  500.             changeBy = -scrollBar->GetMajorScrollUnits(ev);
  501.             break;
  502.     };
  503.  
  504.     FW_CFixed oldValue = FW_IntToFixed(GetValue());
  505.     FW_CFixed newValue = oldValue + changeBy;
  506.     
  507.     if (newValue < scrollBar->GetScrollMin(ev))
  508.         newValue = scrollBar->GetScrollMin(ev);
  509.     else if (newValue > scrollBar->GetScrollMax(ev))
  510.         newValue = scrollBar->GetScrollMax(ev);
  511.  
  512.     SetValue(newValue.AsInt(), TRUE);
  513.  
  514.     scrollBar->ScrollPositionChanged(ev, newValue, newValue - oldValue);
  515. }
  516.  
  517. //========================================================================================
  518. // CLASS FW_CPrivMacPushButtonHelper
  519. //========================================================================================
  520.  
  521. FW_DEFINE_CLASS_M1(FW_CPrivMacPushButtonHelper, FW_CPrivMacControlHelper)
  522.  
  523. //----------------------------------------------------------------------------------------
  524. // FW_CPrivMacPushButtonHelper::FW_CPrivMacPushButtonHelper
  525. //----------------------------------------------------------------------------------------
  526.  
  527. FW_CPrivMacPushButtonHelper::FW_CPrivMacPushButtonHelper(Environment* ev,
  528.                                                         const FW_CClassInfo& classInfo,
  529.                                                         FW_CPushButton* button) :
  530.     FW_CPrivMacControlHelper(ev, classInfo, button)
  531. {
  532.     CheckForInitialize(ev, classInfo);
  533. }
  534.  
  535. //----------------------------------------------------------------------------------------
  536. // FW_CPrivMacPushButtonHelper::~FW_CPrivMacPushButtonHelper
  537. //----------------------------------------------------------------------------------------
  538.  
  539. FW_CPrivMacPushButtonHelper::~FW_CPrivMacPushButtonHelper()
  540. {
  541. }
  542.  
  543. //----------------------------------------------------------------------------------------
  544. // FW_CPrivMacPushButtonHelper::MouseDown
  545. //----------------------------------------------------------------------------------------
  546.  
  547. Boolean FW_CPrivMacPushButtonHelper::MouseDown(WindowPtr window,
  548.                                        const FW_SPlatformPoint& whereMouse,
  549.                                        const FW_SPlatformPoint& controlLocation,
  550.                                        const FW_SPlatformPoint& controlSize)
  551. {
  552.     FW_CPushButton* button = FW_DYNAMIC_CAST(FW_CPushButton, GetGadget());
  553.     FW_ASSERT(button);
  554.  
  555.     SetupControl(window, controlLocation, controlSize);
  556.     
  557.     // ---- Test first that we are really in the control -----
  558.     short part = ::TestControl(GetControlHandle(), whereMouse);
  559.     
  560.     FW_Boolean inControl = (part == kControlButtonPart);
  561.     
  562.     if (inControl)
  563.     {
  564.         // ----- Now we can track -----
  565.         if (::TrackControl(GetControlHandle(), whereMouse, NULL))
  566.             button->ButtonPressed(somGetGlobalEnvironment());
  567.     }
  568.     
  569.     RestoreControl();
  570.     
  571.     return inControl;
  572. }
  573.  
  574. //----------------------------------------------------------------------------------------
  575. // FW_CPrivMacPushButtonHelper::MakeDefaultButton
  576. //----------------------------------------------------------------------------------------
  577.  
  578. void FW_CPrivMacPushButtonHelper::MakeDefaultButton(FW_Boolean isDefault)
  579. {
  580.     FW_CPushButton* button = FW_DYNAMIC_CAST(FW_CPushButton, GetGadget());
  581.     FW_ASSERT(button);
  582.     
  583.     // Default button on the Mac to expand the size of the gadget and draw a
  584.     // standard default button type frame
  585.     
  586.     FW_SPlatformRect margin;
  587.     if (isDefault)
  588.         margin.Set(4, 4, 4, 4);
  589.     else
  590.         margin.Set(0, 0, 0, 0);
  591.     
  592.     SetControlMargin(margin);
  593. }
  594.  
  595. //----------------------------------------------------------------------------------------
  596. // FW_CPrivMacPushButtonHelper::CreateControlHandle
  597. //----------------------------------------------------------------------------------------
  598.  
  599. ControlHandle FW_CPrivMacPushButtonHelper::CreateControlHandle(WindowPtr window,
  600.                                                 const FW_SPlatformPoint& location,
  601.                                                 const FW_SPlatformPoint& size)
  602. {
  603.     // Should move this up to FW_CPrivMacControlHelper and add virtual method for getting
  604.     // the control proc id. That's the only difference. [AMB]
  605.     
  606.     FW_SPlatformRect rect(location.h, location.v,
  607.                           location.h + size.h, location.v + size.v);
  608.     
  609.     return ::NewControl(window, &rect, "\p", true,
  610.                         FW_CScrollBar::kDefaultScrollPos,
  611.                         FW_CScrollBar::kDefaultScrollMin,
  612.                         FW_CScrollBar::kDefaultScrollMax,
  613.                         pushButProc, 0);
  614. }
  615.  
  616. //========================================================================================
  617. // CLASS FW_CPrivMacRadioButtonHelper
  618. //========================================================================================
  619.  
  620. FW_DEFINE_CLASS_M1(FW_CPrivMacRadioButtonHelper, FW_CPrivMacControlHelper)
  621.  
  622. //----------------------------------------------------------------------------------------
  623. // FW_CPrivMacRadioButtonHelper::FW_CPrivMacRadioButtonHelper
  624. //----------------------------------------------------------------------------------------
  625.  
  626. FW_CPrivMacRadioButtonHelper::FW_CPrivMacRadioButtonHelper(Environment* ev,
  627.                                                             const FW_CClassInfo& classInfo,
  628.                                                             FW_CRadioButton* button) :
  629.     FW_CPrivMacControlHelper(ev, classInfo, button)
  630. {
  631.     CheckForInitialize(ev, classInfo);
  632. }
  633.  
  634. //----------------------------------------------------------------------------------------
  635. // FW_CPrivMacRadioButtonHelper::~FW_CPrivMacRadioButtonHelper
  636. //----------------------------------------------------------------------------------------
  637.  
  638. FW_CPrivMacRadioButtonHelper::~FW_CPrivMacRadioButtonHelper()
  639. {
  640. }
  641.  
  642. //----------------------------------------------------------------------------------------
  643. // FW_CPrivMacRadioButtonHelper::MouseDown
  644. //----------------------------------------------------------------------------------------
  645.  
  646. Boolean FW_CPrivMacRadioButtonHelper::MouseDown(WindowPtr window,
  647.                                                 const FW_SPlatformPoint& whereMouse,
  648.                                                 const FW_SPlatformPoint& controlLocation,
  649.                                                 const FW_SPlatformPoint& controlSize)
  650. {
  651.     FW_CRadioButton* button = FW_DYNAMIC_CAST(FW_CRadioButton, GetGadget());
  652.     FW_ASSERT(button);
  653.  
  654.     SetupControl(window, controlLocation, controlSize);
  655.     
  656.     // ---- Test first that we are really in the control -----
  657.     FW_Boolean inControl = (::TestControl(GetControlHandle(), whereMouse) == kControlRadioButtonPart);
  658.     
  659.     if (inControl)
  660.     {
  661.         if (::TrackControl(GetControlHandle(), whereMouse, NULL))
  662.         {
  663.             SetValue(1, TRUE);
  664.             button->ButtonPressed(somGetGlobalEnvironment());
  665.         }
  666.     }
  667.     
  668.     RestoreControl();
  669.     
  670.     return inControl;
  671. }
  672.  
  673. //----------------------------------------------------------------------------------------
  674. // FW_CPrivMacRadioButtonHelper::MakeDefaultButton
  675. //----------------------------------------------------------------------------------------
  676.  
  677. void FW_CPrivMacRadioButtonHelper::MakeDefaultButton(FW_Boolean isDefault)
  678. {
  679.     FW_CPushButton* button = FW_DYNAMIC_CAST(FW_CPushButton, GetGadget());
  680.     FW_ASSERT(button);
  681. }
  682.  
  683. //----------------------------------------------------------------------------------------
  684. // FW_CPrivMacRadioButtonHelper::CreateControlHandle
  685. //----------------------------------------------------------------------------------------
  686.  
  687. ControlHandle FW_CPrivMacRadioButtonHelper::CreateControlHandle(WindowPtr window,
  688.                                                 const FW_SPlatformPoint& location,
  689.                                                 const FW_SPlatformPoint& size)
  690. {
  691.     // Should move this up to FW_CPrivMacControlHelper and add virtual method for getting
  692.     // the control proc id. That's the only difference. [AMB]
  693.     
  694.     FW_SPlatformRect rect(location.h, location.v,
  695.                           location.h + size.h, location.v + size.v);
  696.     
  697.     return ::NewControl(window, &rect, "\p", true,
  698.                         FW_CScrollBar::kDefaultScrollPos,
  699.                         FW_CScrollBar::kDefaultScrollMin,
  700.                         FW_CScrollBar::kDefaultScrollMax,
  701.                         radioButProc, 0);
  702. }
  703.  
  704. #endif
  705.